#ifndef _BC_Comparator_H
#define _BC_Comparator_H

/******************************************************************************
** @file	bc_communicator.h
** @author	Arturo Aguilar
** @author	Andrea Herbas
** @date	Ago 29, 2010
**
** @desc	This class compares two WinObject intances. Specifically, tells
**          if one object is equal or not to another one. We say that two 
**          are equal if both objects have the same state.
**			
**
******************************************************************************/

#include "wmi_reader.h"

template <typename T>
class BC_Comparator
{
public:
	/**
    * Compares two objects, operator == must be implemented.
    *
    * @param first object of the comparision.
    * @param second object of the comparision.
    */
    bool compare(T* t, T* t1)
    {
        return t == t1;
    }
};

template <>
class BC_Comparator<WMI_Share>
{
public:
	/**
    * Compares two WMIShare instances by its state.
    *
    * @param first share instance of the comparision.
    * @param second share instance of the comparision.
    */
    bool compare(WMI_Share* t, WMI_Share* t1)
    {
        bool equal = false;
       
        if(t->getAccessMask() == t1->getAccessMask() &&
            t->getAllowMaximum() == t1->getAllowMaximum() &&  
            t->getCaption() == t1->getCaption() &&   
            t->getDescription() == t1->getDescription() &&
            t->getMaximumAllowed() == t1->getMaximumAllowed() &&
            t->getName() == t1->getName() &&
            t->getPath() == t1->getPath() &&
            t->getStatus() == t1->getStatus() &&
            t->getType() == t1->getType()
           )
        {
            equal = true;
        }
 
        return equal;
    }
};

template <>
class BC_Comparator<WMI_Process>
{
public:
	/**
    * Compares two WMI_Process instances by its state.
    *
    * @param first process instance of the comparision.
    * @param second process instance of the comparision.
    */
    bool compare(WMI_Process* t, WMI_Process* t1)
    {
        bool equal = false;
        if( t->getCaption() == t1->getCaption() &&
            t->getCommandLine() == t1->getCommandLine() &&
		    t->getCreationClassName() == t1->getCreationClassName() &&
			t->getCSCreationClassName() == t1->getCSCreationClassName() &&
			t->getCSName() == t1->getCSName() &&
			t->getDescription() == t1->getDescription() &&
			t->getExecutablePath() == t1->getExecutablePath() &&           
			t->getExecutionState() == t1->getExecutionState() &&           
			t->getHandle() == t1->getHandle() &&          
			t->getHandleCount() == t1->getHandleCount() &&
			t->getInstallDate() == t1->getInstallDate() &&         
			t->getKernelModeTime() == t1->getKernelModeTime() &&        
			t->getMaximumWorkingSetSize() == t1->getMaximumWorkingSetSize() &&          
			t->getMinimumWorkingSetSize() == t1->getMinimumWorkingSetSize() &&        
			t->getName() == t1->getName() &&        
			t->getOSCreationClassName() == t1->getOSCreationClassName() &&          
			t->getOSName() == t1->getOSName() &&           
			t->getOtherOperationCount() == t1->getOtherOperationCount() &&           
			t->getOtherTransferCount() == t1->getOtherTransferCount() &&         
			t->getPageFaults() == t1->getPageFaults() &&        
			t->getPageFileUsage() == t1->getPageFileUsage() &&         
			t->getParentProcessId() == t1->getParentProcessId() &&          
			t->getPeakPageFileUsage() == t1->getPeakPageFileUsage() &&      
			t->getPeakVirtualSize() == t1->getPeakVirtualSize() &&        
			t->getPageFileUsage() == t1->getPageFileUsage() &&        
			t->getPeakWorkingSetSize() == t1->getPeakWorkingSetSize() &&         
			t->getPriority() == t1->getPriority() &&          
			t->getPrivatePageCount() == t1->getPrivatePageCount() &&          
			t->getProcessId() == t1->getProcessId() &&        
			t->getQuotaNonPagedPoolUsage() == t1->getQuotaNonPagedPoolUsage() &&           
			t->getQuotaPagedPoolUsage() == t1->getQuotaPagedPoolUsage() &&           
			t->getQuotaPeakNonPagedPoolUsage() == t1->getQuotaPeakNonPagedPoolUsage() &&           
			t->getQuotaPeakPagedPoolUsage() == t1->getQuotaPeakPagedPoolUsage() &&            
			t->getReadOperationCount() == t1->getReadOperationCount() &&           
			t->getReadTransferCount() == t1->getReadTransferCount() &&          
			t->getSessionId() == t1->getSessionId() &&          
			t->getStatus() == t1->getStatus() &&         
			t->getTerminationDate() == t1->getTerminationDate() &&           
			t->getThreadCount() == t1->getThreadCount() &&         
			t->getUserModeTime() == t1->getUserModeTime() &&           
			t->getVirtualSize() == t1->getVirtualSize() &&         
			t->getWindowsVersion() == t1->getWindowsVersion() &&         
			t->getWorkingSetSize() == t1->getWorkingSetSize() &&
			t->getWriteOperationCount() == t1->getWriteOperationCount() &&          
			t->getWriteTransferCount() == t1->getWriteTransferCount()
			)
		{
			equal = true;
		}
        
        return equal;
    }
};

template <>
class BC_Comparator<WMI_Registry>
{
public:
	/**
    * Compares two WMI_Registry instances by its state.
    *
    * @param first registry instance of the comparision.
    * @param second registry instance of the comparision.
    */
    bool compare(WMI_Registry* t, WMI_Registry* t1)
    {
        bool equal = true;
        
        if(t->getName() != t1->getName())
        {
            equal = false;
        }
        else if(t->getRegistryList().size() != t1->getRegistryList().size())
        {
            equal = false;
        }
        else
        {
            for(int i = 0; i < t->getRegistryList().size(); i++)
            {
                if(t->getRegistryList()[i]->getName() != t1->getRegistryList()[i]->getName())
                {
                    equal = false;                    
                }
            }

            for(int i = 0; i < t->getValueList().size(); i++)
            {
                if(t->getValueList()[i].getName() != t1->getValueList()[i].getName())
                {
                    equal = false;                    
                }
            }
        }      
       
        return equal;
    }
};

template <>
class BC_Comparator<WMI_Disk>
{
public:
	/**
    * Compares two WMI_Disk instances by its state.
    *
    * @param first disk instance of the comparision.
    * @param second disk instance of the comparision.
    */
    bool compare(WMI_Disk* t, WMI_Disk* t1)
    {
        bool equal = true;
        while(true)
        {
            if(t->getName() != t1->getName())
            {
                equal = false;
                break;
            }
            if(t->getCaption() != t1->getCaption())
            {
                equal = false;
                break;
            }
            if(t->getFileSystem() != t1->getFileSystem())
            {
                equal = false;
                break;
            }
            break;
        }
        return equal;
    }
};

template <>
class BC_Comparator<WMI_FileDirectory>
{
public:
	/**
    * Compares two WMI_FileDirectory instances by its state.
    *
    * @param first fileDirectory instance of the comparision.
    * @param second fileDirectory instance of the comparision.
    */
    bool compare(WMI_FileDirectory* t, WMI_FileDirectory* t1)
    {
        bool equal = true;
        while(true)
        {
            if(t->getCaption() != t1->getCaption())
            {
                equal = false;
                break;
            }
            if(t->getDescription() != t1->getDescription())
            {
                equal = false;
                break;
            }
            if(t->getCaption() != t1->getCaption())
            {
                equal = false;
                break;
            }
            if(t->getName() != t1->getName())
            {
                equal = false;
                break;
            }
            if(t->getStatus() != t1->getStatus())
            {
                equal = false;
                break;
            }
            if(t->getInstallDate() != t1->getInstallDate())
            {
                equal = false;
                break;
            }if(t->getCreationDate() != t1->getCreationDate())
            {
                equal = false;
                break;
            }
            if(t->getLastAccessed() != t1->getLastAccessed())
            {
                equal = false;
                break;
            }
            if(t->getLastModified() != t1->getLastModified())
            {
                equal = false;
                break;
            }
            if(t->isWriteable() != t1->isWriteable())
            {
                equal = false;
                break;
            }
            break;
        }
        return equal;
    }
};

#endif
